package com.gs.wzmanager.service.impl;

import com.gs.wzmanager.dao.PortDao;
import com.gs.wzmanager.entity.Port;
import com.gs.wzmanager.service.PortService;
import com.gs.wzmanager.utils.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PortServiceImpl implements PortService {

    @Autowired
    PortDao portDao;

    @Override
    public List<Port> queryAllPort() {
        return portDao.queryAllPort();
    }

    @Override
    public ResponseEntity update(Port port) {
        if (portDao.updatePort(port)) {
            return HttpUtils.buildStringResponse("Ok", HttpStatus.OK);
        } else {
            return HttpUtils.buildStringResponse("ERR", HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity addPort(Port port) {
        if (portDao.addPort(port)) {
            return HttpUtils.buildStringResponse("Ok", HttpStatus.OK);
        } else {
            return HttpUtils.buildStringResponse("ERR", HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

}
